﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KipmeHQ;
using System.IO;

public partial class SiteMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Path.GetFileName(Request.PhysicalPath).Equals("Error.aspx"))
        {
            try
            {
                HeadquarterWSClient service = Application["KipmeHQWS"] as HeadquarterWSClient;
                if (service == null)
                {
                    service = new HeadquarterWSClient();
                }

                departmentdescription[] departments;
                departments = service.getAllDepartments();
                List<MenuItem> _MenuItems = new List<MenuItem>();
                if (departments != null)
                {
                    foreach (departmentdescription item in departments)
                    {
                        _MenuItems.Add(new MenuItem(String.Format("\u2022\t{0} products", item.name), item.name, String.Format("Items.aspx?dept={0}", item.id)));
                    }
                }
                NavigationMenuLeftRepeater.DataSource = _MenuItems;
                NavigationMenuLeftRepeater.DataBind();

                foreach (var item in _MenuItems)
                {
                    NavigationMenu.Items[1].ChildItems.Add(new System.Web.UI.WebControls.MenuItem(item.Title, item.Desc, "", item.Url));
                }
            }
            catch (System.Exception ex)
            {
                if ((Application["ThrowExceptions"] as bool?) == true)
                    throw ex;
            }
        }
    }
}
